-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(client): support local bind for HttpConnector #1500
Conversation
95155c4
to
d433c2e
Compare
I'm not sure what caused the build timeout; I don't think it's related to my code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Don't worry about the test failure, that specific test has been flaky, and I haven't yet been able to track down why it fails when it does...
/// | ||
/// Default is `None`. | ||
#[inline] | ||
pub fn set_local_address(&mut self, addr: Option<IpAddr>) { |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's normally called the local address; see bind(2) at https://linux.die.net/man/2/bind and http://pubs.opengroup.org/onlinepubs/009695399/functions/bind.html . Normally bind
takes a SockAddr
, but for this specific case of binding-before-connecting, it's vanishingly rare that you want to specify the port as well as the IP, which is why I have specified IpAddr
. But it's still an address.
examples/bound_client.rs
Outdated
@@ -0,0 +1,56 @@ | |||
#![deny(warnings)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think my personal preference here would be to not include an entire example file, as it means another thing to adjust when changes are required. We don't have an example for every combination of configuration options...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem - it was just there to show what it would look like. I've removed it now.
82c4bea
to
a80471a
Compare
Woops, test failures are because the |
Add `set_local_address` to the `HttpConnector`. This configures the client to bind the socket to a local address of the host before it connects to the destination. This is useful on hosts which have multiple network interfaces, to ensure the request is issued over a specific interface. Closes hyperium#1498
Right, sorry about that. Fixed now - back to the same timeout error you said not to worry about. |
Thanks so much! |
Thank you! |
Add
set_local_address
to theHttpConnector
.This configures the client to bind the socket to a local address of
the host before it connects to the destination. This is useful on
hosts which have multiple network interfaces, to ensure the request is
issued over a specific interface.
Includes an example to show how it is used and regression-check the API (copied from the existing client example). Please let me know if I should be adding any tests, and if so where.
Closes #1498